package com.ysh.smartplatform.controller;

import com.ysh.smartplatform.dto.R;
import com.ysh.smartplatform.pojo.SysArea;
import com.ysh.smartplatform.service.AreaService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 袁胜虎 on 2022/9/17 17:02
 */
@RestController
@RequestMapping("/areas")
@Api(tags = "地区管理模块")
public class AreaController {
    private AreaService areaService;

    @Autowired
    public void setAreaService(AreaService areaService) {
        this.areaService = areaService;
    }
    @GetMapping("/area")
    public R finaAll(){
        List<SysArea> allArea = areaService.findAllArea();
        return R.OK(allArea);
    }
    @PostMapping("/area")
    public R addArea(@RequestBody SysArea area){
        areaService.interArea(area);
        return R.OK();
    }
    @PostMapping("/area/update")
    public R updateArea(@RequestBody SysArea area){
        areaService.updateArea(area);
        return R.OK();
    }
    @GetMapping("/area/{name}")
    public R findByName(@PathVariable String name){
        return R.OK(areaService.findByName(name));
    }
    @DeleteMapping("/area/{name}")
    public R deleteByName(@PathVariable String name){
        areaService.deleteByName(name);
        return R.OK();
    }
}
